package ar.edu.unlp.info.tesis.database.operator;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.MatchMode;

public class LikeRestriction extends OperatorRestriction {

	MatchMode matchMode = MatchMode.START;

	String value;

	public LikeRestriction(String field, String value) {
		super();
		this.setField(field);
		this.setValue(value);
	}

	/**
	 * el macthmode puede tomar determinados valores
	 * 
	 * @param field
	 * @param value
	 * @param matchMode:
	 *            ANYWHERE, END, EXACT,START
	 */

	public LikeRestriction(String field, String value, String matchMode) {
		super();
		this.setField(field);
		this.setValue(value);
		if (matchMode.equals("END"))
			this.matchMode = MatchMode.END;
		if (matchMode.equals("START"))
			this.matchMode = MatchMode.START;
		if (matchMode.equals("EXACT"))
			this.matchMode = MatchMode.EXACT;
	}

	@Override
	public Criterion getExpresion() {
		return Expression.like(this.getField(), value, matchMode);

	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

}
